define(['jquery','stringUtil'], function ($,stringUtil) {
	
	/**
	 * 打开确认提示框
	 * msg:提示信息
	 * confirmEvent：点击确认按钮响应事件
	 * cancelEvent：点击取消按钮相应事件
	 * 模板在html/conformtask.html页面
	 */
	var _openConfirmTask = function(msg, confirmEvent, cancelEvent) {
		if(typeof msg === 'string' && stringUtil.isNotEmpty(msg)) {
			$(".tipinfo").html(msg);
		}
		$(".conform_default_btn").click(function() {
			//关闭提示框
			$("#shangjia").modal('hide');
			if(typeof confirmEvent === 'function') {
				//响应事件
				confirmEvent();
			}
			$(".conform_default_btn").unbind("click"); 
		});

		$(".cancel_default_btn").click(function() {
			if(typeof cancelEvent === 'function') {
				cancelEvent();
			}
			$(".conform_default_btn").unbind("click"); 
			$(".cancel_default_btn").unbind("click"); 
		});
		//显示确认提示框
		$("#shangjia").modal('show'); 
	}
	
	var _openWindow = function(windowId, confirmId, confirmEvent, cancenId, cancelEvent) {
		if(typeof confirmEvent === 'function') {
			$(confirmId).unbind("click").click(function() {
				//响应事件
				confirmEvent();
			});
		}
		
		if(typeof cancelEvent === 'function') {
			$(cancenId).unbind("click").click(function() {
				cancelEvent();
				//确认按钮解除绑定
				//$(confirmId).unbind("click"); 
				//取消按钮解除绑定
				//$(cancenId).unbind("click");
			});
		}
		
		//显示确认提示框
		$(windowId).modal('show'); 
	}
	
	var _modal_alert = function(info){
		if($("#modal-alert").length == 0) {
			$(document.body).append(
			'<div class="modal fade" id="modal-alert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">'+
			  '<div class="modal-dialog">'+
			  		'<div class="modal-content">'+
			  			'<div class="modal-header">'+
			  				'<h4 class="modal-title" id="myModalLabel">提示</h4>'+
			  			'</div>'+
			  			'<div class="modal-body">'+
			  				'<div class="tipinfo">'+info+'</div>'+
			  			'</div>'+
			  			'<div class="modal-footer">'+
			  				'<button type="button" class="btn btn-primary">确定</div>'+
			  			'</div>'+
			  		'</div>'+
			  '</div>'+
			'</div>'
			);
			
		} else {
			$("#modal-alert .tipinfo").html(info);
		}
		$("#modal-alert").modal('show');
		
		$("#modal-alert").unbind("click").click(function() {
			$("#modal-alert").modal('hide');
		});
	}
	
	return{
		openConfirmTask:function(msg, confirmEvent, cancelEvent) {
			_openConfirmTask(msg, confirmEvent, cancelEvent);
		},
		
		openWindow:function(windowId, confirmId, confirmEvent, cancenId, cancelEvent) {
			_openWindow(windowId, confirmId, confirmEvent, cancenId, cancelEvent);
		},
		modal_alert:function(title,info,speed,hideFunction) {
			_modal_alert(title,info,speed,hideFunction);
		}
	};
});